package com.suxin.thread.schedule;

import com.suxin.thread.schedule.domain.TaskWithBlobs;
import com.suxin.thread.schedule.task.TaskService;

import java.util.concurrent.CountDownLatch;

/**
 * @author Tang
 * @classname RunnableTask
 * @description [  ]
 * @date 2021/3/16 21:18
 */
public class RunnableTask implements Runnable,LifeCycle{

    private TaskService taskService;

    private TaskWithBlobs taskWithBlobs;

    private CountDownLatch countDownLatch;

    public RunnableTask(TaskWithBlobs task, TaskService taskService, CountDownLatch countDownLatch) {
        this.taskWithBlobs = task;
        this.taskService = taskService;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        try {
            this.before();
            taskService.executeTask(taskWithBlobs.getId());
            this.after();
        }finally {
            countDownLatch.countDown();
        }
    }

    @Override
    public void before() {

    }

    @Override
    public void after() {

    }
}